#ifndef CAMERAGRAPHICSVIEW_H
#define CAMERAGRAPHICSVIEW_H

#include <QGraphicsView>
#include <QLabel>
#include "GxIAPI.h"
#include "DxImageProc.h"

#include "cameraimageitem.h"
#include "resultimageitem.h"

class CameraGraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    CameraGraphicsView(QWidget *parent = 0);
    ~CameraGraphicsView();

public:
    //设置视觉窗口的图像
    void SetImage(const QImage &qImage);
    void SetImage(GX_FRAME_CALLBACK_PARAM* pFrame);

    void SetInfo(QString info){
        m_strInfo = info;
        m_pInfoLabel->setText(m_strInfo);
    }

signals:
    void ShowNewImage();

private:
    bool InitWidget();

public slots:
    void DoShowNewImage();
    //视图居中显示
    void onCenter();
    //视图缩放
    void onZoom(float fScaleFactor);

private:
    //辅助函数：自适应大小
    void fitFrame();

public:
    void setBackground(bool enabled = true, bool invertColor = false);

private:
    QString             m_strInfo;
    double              m_dZoomValue = 1;

    QPixmap             m_tilePixmap = QPixmap(36, 36); //背景图片方格

protected:
    virtual void paintEvent(QPaintEvent *event) override;
    virtual void resizeEvent(QResizeEvent *event) override;
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;

public:
    void                SetImageResult(int nRet);
    void                ClearImage();

public:
    QImage&             GetImage(){return m_qImage;}

private:
    QGraphicsScene      *m_pScene;          //场景
    CameraImageItem     *m_pImageItem;      //图像元素
    ResultImageItem     *m_pResultImagetItem;
    QPixmap             m_Image;            //视觉窗口所显示的图像
    QImage              m_qImage;

    QWidget             *m_pInfoWidget;     //视觉窗口左上方
    QLabel              *m_pInfoLabel;      //显示信息标签
};

#endif // CAMERAGRAPHICSVIEW_H
